package yxy.game.pm2.gm.url;

import com.alibaba.fastjson.JSONObject;

import yxy.apple.http.server.business.Business;
import yxy.apple.http.server.business.BusinessType;
import yxy.game.pm2.bean.area.ChatChannelType;
import yxy.game.pm2.chat.module.ChatHandle;
import yxy.game.pm2.gm.result.GMResult;
import yxy.game.pm2.gm.result.GMResult.GMError;

/** GM发送消息接口 */
@BusinessType(code = "SENDMESSAGE")
public class GMSendMessage implements Business {

	@Override
	public String name() {
		return "gm";
	}

	@Override
	public JSONObject handle(JSONObject request) throws Exception {
		int channel = request.getIntValue("channel");
		int areaId = request.getIntValue("areaId");
		String text = request.getString("text");

		ChatChannelType channelType = ChatChannelType.forNumber(channel);
		if (channelType == null) {
			return new GMResult().result(new JSONObject(), GMError.Err_发消息_频道错误);
		}
		switch (channelType) {
		case CHAT_AREA:
		case CHAT_SCROLL:
		case CHAT_SYS:
		case CHAT_WORLD:
			break;
		default:
			return new GMResult().result(new JSONObject(), GMError.Err_发消息_频道错误);
		}

		ChatHandle.sendInner(null, areaId, channelType, text);

		return new GMResult().result(new JSONObject(), GMError.OK);
	}

	@Override
	public Business clone() throws CloneNotSupportedException {
		return (Business) super.clone();
	}

}
